package com.jin.lazytool.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jin.lazytool.customevent.CustomEvent;
import com.jin.lazytool.handler.ILoopHandler;
import com.jin.lazytool.handler.LoopType;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;

import java.awt.*;
import java.time.LocalDateTime;

public class LoopStartEvent extends ILoopEvent{

    private String loopNum;

    // 按照次数
    private Integer loopCount;

    // 按照计时
    private long timer;

    // 截止系统时间
    private LocalDateTime dateTime;

    private LoopType type;

    @JsonIgnore
    private Integer jumpCount;


    @JsonIgnore
    private ILoopHandler handler;

    public void initHandler(){
        handler = type.getHandler().newHandler(loopCount,timer,dateTime, getLua(),jumpCount,getTime());
    }


    @Override
    public int execute(Robot robot, int index) throws NoSuchMethodException,InterruptedException{
        return handler.execute(index);
    }

    @Override
    public Pane initDesc() {
        FlowPane pane = new FlowPane();
        pane.setStyle("-fx-pref-height: 26;");
        String init;
        Label label = new Label();
        label.setStyle("-fx-pref-height: 26;");
        init = "[" + loopNum + "] 循环开始,类型:" + type.getDesc();
        label.setText(init);
        pane.getChildren().addAll(label);
        CustomEvent.addLoopEvent(this);
        return pane;
    }


    @Override
    public void show() {

    }

    public String getLoopNum() {
        return loopNum;
    }

    public void setLoopNum(String loopNum) {
        this.loopNum = loopNum;
    }


    public Integer getLoopCount() {
        return loopCount;
    }

    public void setLoopCount(Integer loopCount) {
        this.loopCount = loopCount;
    }

    public long getTimer() {
        return timer;
    }

    public void setTimer(long timer) {
        this.timer = timer;
    }

    public LocalDateTime getDateTime() {
        return dateTime;
    }

    public LoopType getType() {
        return type;
    }

    public void setType(LoopType type) {
        this.type = type;
    }

    public void setDateTime(LocalDateTime dateTime) {
        this.dateTime = dateTime;
    }

    public Integer getJumpCount() {
        return jumpCount;
    }

    public void setJumpCount(Integer jumpCount) {
        this.jumpCount = jumpCount;
    }

    public LoopStartEvent buildNew(){
        LoopStartEvent event = new LoopStartEvent();
        event.setLoopNum(loopNum);
        event.setTimer(timer);
        event.setDateTime(dateTime);
        event.setType(type);
        event.setLoopCount(loopCount);
        event.setJumpCount(jumpCount);
        return event;
    }
}
